#include "ipcnetworkmanager.h"

void IPCNetworkManager::onRecieveServerData(const QByteArray & data)
{
    QByteArray args;
    mXml->packetArgs2(args, (QByteArray &)data);
    QString cmd(SLOT(onRecieveServerData(const QByteArray &)));
    send_request(cmd,args,N2L);
}

void IPCNetworkManager::onServerNotify(int code)
{
    QByteArray args;
    mXml->packetArgs1(args,code);
    QString cmd(SLOT(onServerNotify(int)));
    send_request(cmd,args,N2L);
}

void IPCNetworkManager::onReceivedData(const QString & ip, const QByteArray & data)
{
    QByteArray args;
    mXml->packetArgs3(args, ip,data);
    QString cmd(SLOT(onReceivedData(const QString &, const QByteArray &)));
   send_request(cmd, args,N2L);
}

void IPCNetworkManager::onNotify(const QString & ip, int code)
{
    QByteArray args;
    mXml->packetArgs4(args, ip,code);
    QString cmd(SLOT(onNotify(const QString &, int)));
    send_request(cmd , args,N2L);
}

int IPCNetworkManager::init()
{
    AsyCop::init();
    connect(mNetwk, SIGNAL(recieveServerData(QByteArray)), this, SLOT(onRecieveServerData(const QByteArray &)));
    connect(mNetwk, SIGNAL(serverNotify(int)), this, SLOT(onServerNotify(int)));    
    connect(mNetwk, SIGNAL(recieveData(QString, QByteArray)),this, SLOT(onReceivedData(const QString &, const QByteArray &)));
    connect(mNetwk, SIGNAL(notify(QString, int)),this, SLOT(onNotify(const QString &, int)));
}
int IPCNetworkManager::do_request(QString &cmd, QByteArray &args)
{
    AsyCop::do_request(cmd,args);
     if( cmd == SLOT(onSendServerData(QByteArray)))
     {
            QByteArray data;
            mXml->parseArgs2(args,data);
            printf("do_request,onsendserverdata arg:%s\n",data.data());
            mNetwk->onSendServerData(data);
     }
     else if( cmd == SLOT(onSendData(QString, QByteArray)))
     {
            QString ip;
            QByteArray data;
            mXml->parseArgs3(args,ip,data);
            printf("do_request,onSendData arg:%s:%s\n",ip.toAscii().data(),data.data());
            mNetwk->onSendData(ip,data);
     }
}

